﻿using System;
using System.Collections;
using System.Collections.Generic;

public class FSMParam
{
    private Dictionary<Type, IDictionary> m_ParamDict = new Dictionary<Type, IDictionary>();

    /// <summary>
    /// 获取参数
    /// </summary>
    public T GetParam<T>(string key) where T : struct
    {
        if (!m_ParamDict.TryGetValue(typeof(T), out var idict))
            return default;
        var dict = idict as Dictionary<string, T>;
        dict.TryGetValue(key, out var value);
        return value;
    }

    /// <summary>
    /// 设置参数，当省略类型时请注意是否存在隐式转换
    /// </summary>
    public void SetParam<T>(string key, T value) where T : struct
    {
        var type = typeof(T);
        if (!m_ParamDict.TryGetValue(type, out var idict))
        {
            idict = new Dictionary<string, T>();
            m_ParamDict.Add(type, idict);
        }
        var dict = idict as Dictionary<string, T>;
        dict[key] = value;
    }

    /// <summary>
    /// 重置，清空所有存储的参数
    /// </summary>
    public void Reset()
    {
        foreach (var kvp in m_ParamDict)
        {
            kvp.Value.Clear();
        }
    }
}